let runTimeStorageData = {};
/**
 * 本地存储-存
 * @param {String} k key
 * @param {any} data
 * @param {Object} options StorageOptions
 */
export function setStorage(k, data, options) {
    if (!k)
        return;
    const { expired, runTime } = { ...options };
    const d = { t: Date.now(), expired, data };
    runTime
        ? (runTimeStorageData[k] = d)
        : uni.setStorageSync(k, JSON.stringify(d));
}
/**
 * 本地存储-取
 * @param {String} k key
 * @param {Object} options StorageOptions
 * @returns any
 */
export function getStorage(k, options) {
    if (!k)
        return null;
    const { runTime, expired } = { ...options };
    let d = runTime ? runTimeStorageData[k] : uni.getStorageSync(k);
    if (!d)
        return d;
    if (!runTime)
        d = JSON.parse(d);
    const exp = expired || d.expired;
    if (exp && Date.now() - d.t > exp)
        return null;
    return d.data;
}
/**
 * 移除某一项本地存储
 * @param k key
 * @param options StorageOptions
 */
export function removeStorage(k, options) {
    const { runTime } = { ...options };
    runTime ? delete runTimeStorageData[k] : uni.removeStorageSync(k);
}
/**
 * 清空本地存储
 * @param options StorageOptions
 */
export function clearStorage(options) {
    const { runTime } = { ...options };
    runTime ? (runTimeStorageData = {}) : uni.clearStorageSync();
}
